import { createApp } from "vue";
import { createPinia } from "pinia";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import router from "./router";
import App from "./App.vue";

const app = createApp(App);

// 安装 Pinia
app.use(createPinia());

// 安装 Element Plus
app.use(ElementPlus, {
  locale: zhCn,
});

// 注册 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component as any);
}

// 安装路由
app.use(router);

// 挂载应用
app.mount("#app");

// 初始化主题系统
import { useThemeStore } from "./stores/theme";

// 等待DOM加载完成后初始化主题
if (typeof window !== 'undefined') {
  const themeStore = useThemeStore();
  themeStore.initTheme();
}

// 初始化认证系统
import { useAuthStore } from "./stores/auth";

// 等待DOM加载完成后初始化认证状态
if (typeof window !== 'undefined') {
  const authStore = useAuthStore();
  authStore.initializeAuth();
}
